package com.kongjs.common.mybatis.tenant;

import org.springframework.util.ObjectUtils;

public class TenantContextHolder {
    private static final ThreadLocal<String> TENANT_ID_CONTEXT_HOLDER = new ThreadLocal<>();
    private static final ThreadLocal<Boolean> TENANT_IGNORE_CONTEXT_HOLDER = new ThreadLocal<>();

    public static void setTenantId(String tenantId) {
        TENANT_ID_CONTEXT_HOLDER.set(tenantId);
    }

    public static String getTenantId() {
        return TENANT_ID_CONTEXT_HOLDER.get();
    }

    public static void clearTenantId() {
        TENANT_ID_CONTEXT_HOLDER.remove();
    }

    public static void setIgnore() {
        TENANT_IGNORE_CONTEXT_HOLDER.set(true);
    }

    public static boolean getIgnore() {
        Boolean b = TENANT_IGNORE_CONTEXT_HOLDER.get();
        return !ObjectUtils.isEmpty(b) && b;
    }

    public static void clearIgnore() {
        TENANT_IGNORE_CONTEXT_HOLDER.set(false);
    }
}
